import  requests
import json
 
content = "Several years ago,i went to study python in beijing"
 
language_type = "en"
url = "https://translation.googleapis.com/language/translate/v2"
data = {
    'key': 'AIzaSyAfVP30a7wQGIrY2sLS0pdnh-ZwWG6AOhM', #你自己的api密钥
    'source': language_type,
    'target': 'zh-cn',
    'q': content,
    'format': 'text'
}
headers = {'X-HTTP-Method-Override': 'GET'}
response = requests.post(url, data=data, headers=headers)
res = response.json()
text = res["data"]["translations"][0]["translatedText"]
print(text)